/*
//	CP2013 Traffic Simulator Assignment :: (MVC) Model :: Intersection Class
//	Copyright (c) 2010, Adam Rehn
//
//	This class models a single intersection.
*/

#ifndef _MODEL_INTERSECTION_H
#define _MODEL_INTERSECTION_H

//Required for the common enums and types
#include "common.h"

//Include other components
#include "trafficlight.h"
#include "rectangle.h"
#include "zone.h"
#include "operators.h"

//We are using STL vectors
#include <vector>
using std::vector;

//Theis represents a single phase in the intersection's cycle
struct intersectionState
{
	lightstate lightNS;
	lightstate lightWE;
	vector<zone> zones;
};

class intersection
{
	public:
		//Constructor
		intersection(rectangle area = rectangle(0,0,0,0), unsigned int greenLength = DEFAULT_GREEN_LENGTH);
		
		//THESE CAN BE REPLACED WITH A RECTANGLE
		/*
		coordinate         anchor;
		unsigned int       width;
		unsigned int       height;
		*/
		rectangle area;
		
		unsigned int       greenLength;
		
		//Use this to cycle the intersection lights to the next state
		void cycleState();
		
		//This will return true if one of the lights is yellow
		bool yellowOn() const;
		
		//These are derived from the intersection state and are for rendering niceties only
		trafficlight       lightNS;
		trafficlight       lightWE;
		
	private:
		
		//The intersection state and the cycle index
		intersectionState  state;
		unsigned int       cycleIndex;
		
		//All of the possible states the intersection supports, indexed numerically
		vector<intersectionState> statesCycle;
		
		//Helper functions
		void setState(unsigned int n);
};

#endif
